<template>
  <div class="animate">
    <div class="animate-box">
      <div class="cycle-1">
        <img :src="appInfo.headImgUrl" alt="">
        <div class="ball-box">
          <div class="ball"></div>
        </div>
      </div>
      <div class="cycle-2"></div>
      <div class="cycle-3"></div>
    </div>
    <div class="time">等待时间:{{time}}</div>
    <button plain="true" class="btn-success" @click.stop="cancle">取消匹配</button>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
  props: ["matchBtn", "reStart"], //开关
  data() {
    return {
      timer: null,
      time: 0
    };
  },
  computed:{
    ...mapState(["appInfo"]),
  },
  watch: {
    matchBtn(val) {
      console.log('监听wait')
      if (val) {
        this.timer = setInterval(() => {
          this.time++;
        }, 1000);
      } else {
        clearInterval(this.timer);
        this.time = 0;
      }
    },
    // time(val) {
    //   if (val <= 0) {
    //     this.timeOut();
    //     clearInterval(this.timer);
    //     this.time = 10;
    //   }
    // },
    // reStart() {
    //   this.time = 10;
    //   this.timer = setInterval(() => {
    //     this.time--;
    //   }, 1000);
    // }
  },
  methods: {
    timeOut() {
      //匹配超时
      this.$emit("timeOut");
    },
    cancle() {
      //取消匹配
      clearInterval(this.timer);
      this.time = 10;
      this.$emit("cancleMatch");
    }
  }
};
</script>

<style lang="scss" scoped>
@import url("../../../scss/public.scss");
.animate {
  position: relative;
}
.time {
  text-align: center;
  margin-bottom: 45rpx;
  color: #000;
  font-size: 48rpx;
  line-height: 1;
}
.animate-box {
  width: 572rpx;
  height: 572rpx;
  margin-bottom: 120rpx;
  position: relative;
  & > div {
    position: absolute;
    width: 360rpx;
    height: 360rpx;
    border: 8rpx solid #67c29f;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    top: 50%;
    left: 50%;
  }
  .cycle-1 {
    display: flex;
    justify-content: center;
    align-items: center;
    img {
      width: 184rpx;
      height: 184rpx;
      border: 6rpx solid #fff;
      border-radius: 50%;
      box-shadow: 0 0 20rpx 0rpx rgba(#000, 0.5);
    }
    .ball-box {
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
      animation: rotate 3s linear infinite;
      .ball {
        width: 34rpx;
        height: 34rpx;
        background: #67c29f;
        border-radius: 50%;
        position: absolute;
        bottom: -17rpx;
        left: 50%;
        margin-left: -17rpx;
      }
    }
  }
  .cycle-2 {
    animation: amplification-1 2s linear infinite;
    border-width: 5rpx;
  }
  .cycle-3 {
    animation: amplification-2 2s linear infinite;
    border-width: 3rpx;
  }
}

@keyframes rotate {
  0% {
    transform: rotate(0);
  }
  25% {
    transform: rotate(90deg);
  }
  60% {
    transform: rotate(180deg);
  }
  80% {
    transform: rotate(270deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes amplification-1 {
  0% {
    transform: translate(-50%, -50%) scale(1);
    // border-width: 8rpx;
    opacity: 0.8;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.5);
    // border-width: 5rpx;
    opacity: 0;
  }
}

@keyframes amplification-2 {
  0% {
    transform: translate(-50%, -50%) scale(1);
    // border-width: 8rpx;
    opacity: 0.6;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.1);
    // border-width: 3rpx;
    opacity: 0;
  }
}
</style>
